package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_14_Training {
    //字符串中最多数目的子序列
    public long maximumSubsequenceCount(String text, String pattern) {
        int n = text.length();
        int[] sums = new int[n+1];
        for (int i = n-1; i >= 0; i--) {
            sums[i] = sums[i+1];
            if (text.charAt(i) == pattern.charAt(1)) {
                sums[i]++;
            }
        }
        int sum = 0;
        long m = 0;
        for (int i = 0; i < n; i++) {
            if (text.charAt(i) == pattern.charAt(0)) {
                sum++;
                m += sums[i+1];
            }
        }
        return m + Math.max(sum, sums[0]);
    }
}
